package com.xyebank.ledger.service.lkl.adapter;

import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
import org.springframework.stereotype.Component;

import com.xyebank.ledger.db.entitys.LApplicationInf;
import com.xyebank.ledger.service.common.conveter.ApplyBeanConverter;
import com.xyebank.ledger.service.constant.CommonConstant;
import com.xyebank.ledger.service.constant.ProductConstant;
import com.xyebank.ledger.util.DateConverter;
import com.xyebank.ledger.util.IDUtil;
import com.xyebank.ledger.util.StatusConvertUtil;
import com.xyebank.ledger.vo.deal.LKLCashInfVo;

// TODO
// finish
@Component(value = "lklApplyBeanConverter")
public class LKLApplyBeanConverter implements ApplyBeanConverter<LKLCashInfVo> {
    
    // 不能采取注入方式
    private DateConverter dateConverter = new DateConverter();
    
    ModelMapper modelMapper = new ModelMapper();


    class LKLApplyPropertyMap extends PropertyMap<LKLCashInfVo, LApplicationInf> {
        protected void configure() { //注意　不要有重复的映射，不然会报错
            // 解决自动映射id问题
            map(source.getContractNo(), destination.getOrgOrderNo());
            map(source.getMblNo(), destination.getMblNo());
            using(dateConverter).map(source.getApplyTime(), destination.getApplyTime());
            map(source.getCompleteTime(), destination.getCreditTime());
            
       }
    }

    public LKLApplyBeanConverter() {
        modelMapper.addMappings(new LKLApplyPropertyMap());
    }

    @Override
    public LApplicationInf covert(LKLCashInfVo x) {
        LApplicationInf entity = modelMapper.map(x, LApplicationInf.class);
        /**
         * channel YDSJD1-手机贷； YDSJD2-享宇钱包；
         */
        entity.setId(IDUtil.generateId(x.getId().toString(), "lkl"));
        entity.setDataSource(x.getChannel().equals("YDSJD2") ? CommonConstant.JRY_STR : CommonConstant.SJD_STR);
        entity.setXyOrgNo(ProductConstant.LKL_LOAN_ORG);
        entity.setXyProductNo(ProductConstant.LKL_LOAN_PROD_ID);
        entity.setStatus(StatusConvertUtil.convertApplyStatus(x.getContractStatus()));
        return entity;
    }
    
}
